// (C) Andreas Kaiser 2008

#ifndef _RF02_H
#define _RF02_H

//-----------------------------------------------------------------------------
// RF02 definitions

#define RF02CFG				0x8000
#define RF02CFG_Frequency433		(1<<11)
#define RF02CFG_Frequency868		(2<<11)
#define RF02CFG_Frequency915		(3<<11)
#define RF02CFG_Clock1000KHz		(0<<8)
#define RF02CFG_Clock1250KHz		(1<<8)
#define RF02CFG_Clock1666KHz		(2<<8)
#define RF02CFG_Clock2000KHz		(3<<8)
#define RF02CFG_Clock2500KHz		(4<<8)
#define RF02CFG_Clock3333KHz		(5<<8)
#define RF02CFG_Clock5000KHz		(6<<8)
#define RF02CFG_Clock10000KHz		(7<<8)
#define RF02CFG_CrystalLoad(pF)		((int)(((pF)-8.5)*2)<<4)	/* 8.5..16.0 */
#define RF02CFG_InvertedFSK		(1<<3)
#define RF02CFG_FrequencyShift(khz)	((khz)/30-1)			/* 30..210 */

#define RF02PWR				0xC000
#define RF02PWR_AutostartFreq		(1<<7)
#define RF02PWR_AutostartAmp		(1<<6)
#define RF02PWR_Crystal			(1<<5)
#define RF02PWR_Synthesizer		(1<<4)
#define RF02PWR_Amplifier		(1<<3)
#define RF02PWR_LowBattery		(1<<2)
#define RF02PWR_Wakeup			(1<<1)
#define RF02PWR_DisableClockOutput	(1<<0)

#define RF02FREQ			0xA000
#define RF02FREQ_Calc(MHz,c1,c2)	((int)(((400.0*(MHz))/c1-4000.0*c2)))
#define RF02FREQ_433(MHz)		RF02FREQ_Calc(MHz,1,43)
#define RF02FREQ_868(MHz)		RF02FREQ_Calc(MHz,2,43)
#define RF02FREQ_915(MHz)		RF02FREQ_Calc(MHz,3,30)

#define RF02RATE(bps)			(0xC800 | (int)(10e6/29/(bps)-0.5)) /* 2400..115200 */

#define RF02AMP(db)			(0xB000 | ((-(db)/3)&7)<<8)	/* 0..-21 */
#define RF02AMP2(val)			(0xB000 | (val)<<8)		/* 0..7 */

#define RF02LBTX			0xC200
#define RF02LBTX_DisableWakeupCalib	(1<<7)
#define RF02LBTX_EnableBitSync		(1<<5)
#define RF02LBTX_Voltage(V)		(((int)((V)-2.2)*10)&0x1F)	/* 2.2..5.4V */

#define RF02SLEEP			0xC400
#define RF02SLEEP_Delay(clocks)		((n)&0xFF)			/* 0..255 clocks */

#define RF02WAKE			0xE000
#define RF02WAKE_Prescaler(n)		(((n)&0x1F)<<8)			/* 0..31 */
#define RF02WAKE_Timer(ms)		((ms)&0xFF)			/* 0..255 */

#define RF02SEND			0xC6

#define RF02STAT			0x00
#define RF02STAT_POR			(1<<7)
#define RF02STAT_LBD			(1<<2)
#define RF02STAT_WKUP			(1<<1)
#define RF02STAT_NIRQ			(1<<0)

#endif //_RF02_H
